package com.test.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.stereotype.Component;
import org.springframework.util.StringValueResolver;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/11/27 19:06
 */
@Component
public class Red implements ApplicationContextAware, BeanNameAware, EmbeddedValueResolverAware {
    StringValueResolver resolver;
    private ApplicationContext context;
    private String beanName;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
        System.out.println("传入的ioc容器:" + context);
    }

    @Override
    public void setBeanName(String name) {
        this.beanName = name;
        System.out.println("当前bean的名字：" + name);
    }

    @Override
    public void setEmbeddedValueResolver(StringValueResolver resolver) {
        this.resolver = resolver;
        String value = resolver.resolveStringValue("你好${os.name}, 我是#{20*18}");
        System.out.println("解析的字符串：" + value);
    }
}
